package com.zxj.test.service;

import com.zxj.test.common.exception.EmployeeNotExistException;
import com.zxj.test.mapper.EmployeeMapper;
import com.zxj.test.model.Employee;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author zxj
 * @date 2020/7/18
 */
@Service
public class EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    public Employee getEmp(int id) {
        checkId(id);
        return employeeMapper.selectEmployee(id);
    }

    public boolean addEmp(Employee employee) {
        return employeeMapper.insertEmployee(employee) > 0;
    }

    public boolean modifyEmp(Employee employee) {
        return employeeMapper.updateEmployee(employee) > 0;
    }

    public boolean removeEmp(int id) {
        checkId(id);
        return employeeMapper.deleteEmployee(id) > 0;
    }

    private void checkId(int id) {
        int min = 0;
        if (id <= min) {
            throw new EmployeeNotExistException("员工id不能小于" + min);
        }
    }
}
